package tothreedesignmodel.prototype;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author lzhphantom
 * @Description
 * @Date 创建于 16:26 2020/7/17
 * @Modified
 */
public class ProtoTypeManager {
    private Map<String,Shape> ht=new HashMap<>();
    public ProtoTypeManager(){
        ht.put("Circle",new Circle(3));
        ht.put("Square",new Square(3));
    }
    public void addShape(String key,Shape obj){
        ht.put(key,obj);
    }
    public Object getShape(String key) throws CloneNotSupportedException {
        return ht.get(key).clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        ProtoTypeManager manager = new ProtoTypeManager();
        Circle circle = (Circle)manager.getShape("Circle");
        circle.countArea();
        Square square = (Square)manager.getShape("Square");
        square.countArea();
    }
}
